package com.classtimer.controller;

import java.util.Calendar;
import java.util.Date;

import com.classtimer.Model.SchoolMac;
import com.classtimer.Model.StudentInfo;
import com.jfinal.core.Controller;

public class DataController extends Controller{

	public void timerStart() {
		String getLocalMac = getPara("localMac");
		String getRouterMac = getPara("routerMac");

		int weekday = getWeekday();
		StudentInfo student = StudentInfo.dao.findStudent(getLocalMac); 
		if(student != null) {
			if(SchoolMac.dao.isSchoolNet(getRouterMac)) {
				student.addTimeByWeekday(weekday,0.05);
				setAttr("result", "YES");
				setAttr("msg", "学习使你快乐");
			}else {
				setAttr("result", "NO");
				setAttr("msg", "又在寝室堕落");
			}
		}else {
			setAttr("result", "NO");
			setAttr("msg", "请联系导生大大修改mac");
		}
		renderJson();
	}
	
	/**
	 * 得到今天是星期几
	 * @return 	1:星期天  2:星期一  依次类推
	 */
	private int getWeekday() {
		Date today = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(today);
		return calendar.get(Calendar.DAY_OF_WEEK);
	}
}
